package com.example.hanfu_bk.mapper;

import com.example.hanfu_bk.pojo.Hanfu;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface HanfuMapper {

    // 插入所有字段
    @Insert("INSERT INTO hanfu_3d(" +
            "user_id, color, colorName, color_1, color_1Name, " +
            "color_2, color_2Name, style, styleName, pattern, " +
            "patternName, design, designName, fabric, fabricName" +
            ") VALUES(" +
            "#{userId}, #{color}, #{colorName}, #{color1}, #{color1Name}, " +
            "#{color2}, #{color2Name}, #{style}, #{styleName}, #{pattern}, " +
            "#{patternName}, #{design}, #{designName}, #{fabric}, #{fabricName}" +
            ")")
    @Options(useGeneratedKeys = true, keyProperty = "id")  // 自动生成主键并回显
//    查询用户的定制记录
    int insertHanfu(Hanfu hanfu);
    @Select("SELECT id, user_id AS userId, color, colorName, color_1 AS color1, color_1Name AS color1Name, color_2 AS color2, color_2Name AS color2Name, style, styleName, pattern, patternName, design, designName, fabric, fabricName, created_at AS createdAt FROM hanfu_3d WHERE user_id = #{userId} ORDER BY created_at DESC")
    List<Hanfu> selectByUserId(Integer userId);
//    根据用户ID和记录ID查询（用于权限校验）
    @Select("SELECT id FROM hanfu_3d WHERE user_id = #{userId} AND id = #{recordId}")
    Hanfu selectByUserIdAndRecordId(
            @Param("userId") Integer userId,
            @Param("recordId") Integer recordId
    );
//    根据用户ID和记录ID删除
    @Delete("DELETE FROM hanfu_3d WHERE user_id = #{userId} AND id = #{recordId}")
    int deleteByUserIdAndRecordId(
            @Param("userId") Integer userId,
            @Param("recordId") Integer recordId
    );
}